package com.general.framework.cc.lock;

public class T10 {
    private int num = 0;

    public void t1() {
        synchronized (this) {
            System.out.println("now in t1 111====" + Thread.currentThread().getName());
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            synchronized (Integer.valueOf(num)) {
                System.out.println("now in t1 222====" + Thread.currentThread().getName());
                num++;
            }
        }
    }

    public void t2() {
        synchronized (Integer.valueOf(num)) {
            System.out.println("now in t2 111====" + Thread.currentThread().getName());
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            synchronized (this) {
                System.out.println("now in t2 222====" + Thread.currentThread().getName());
                num++;
            }
        }
    }

    public static void main(String[] args) {
        T10 t10 = new T10();
        new Thread(t10::t1).start();
        new Thread(t10::t2).start();
    }
}
